from django.db import models
#导入内建的user模型
from django.contrib.auth.models import User
#timezone用于处理时间
from django.utils import timezone


#博客文章模型
class ArticlePost(models.Model):
    title = models.CharField(max_length=100,verbose_name='文章标题')
    author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='作者')
    body = models.TextField()
    create_time = models.DateTimeField(default=timezone.now)
    update_time = models.DateTimeField(default=timezone.now)
    class Meta:
        #ordering指定模型返回排列顺序，-created 按倒序排
        ordering = ['-create_time']
    def __str__(self):
        return self.title